<!--
 * @Descripttion: 
 * @version: 
 * @Author: lehaixia
 * @Date: 2023-05-24 15:30:19
 * @LastEditors: lehaixia
 * @LastEditTime: 2023-05-25 09:27:54
-->
<template>
  <List ref="qmpList" v-model:finished="finished" :reset-fun="resetData" :load="load" :refresh="load">
    <Item v-for="(item, i) in list" :key="i" :item-data="item" :dictData="dictData" />
  </List>
</template>
<script lang="ts">
  import { ref, reactive, toRefs, defineComponent } from 'vue'
  // import { useRouter } from 'vue-router'
  import List from '@/components/List/index.vue'
  import Item from './Item.vue'
  import { getList } from '@/apis/attractInvestment/potentialCustomerMarketChange'
  import { getDictByPatchType } from '@/apis/dataDict'

  export default defineComponent({
    name: 'PotentialCustomerMarketList',
    components: { List, Item },
    props: {
      id: {
        type: String,
        default: ''
      }
    },
    setup(props) {
      const qmpList = ref()
      // const $router = useRouter()
      const datas = reactive({
        list: [],
        finished: false,
        dictData: {}
      })
      const load = async (page: number, rows: number) => {
        const filtersRaw: object[] = [
          { id: 'intendedCustomerId', property: 'intendedCustomerId', operator: '=', value: props.id }
        ]

        const paramsData = {
          page,
          rows,
          sort: 'changeTime',
          order: 'desc',
          filtersRaw,
          paramsRaw: {},
          sortersRaw: [],
          pageFlag: true
        }
        return getList(paramsData).then((res: any) => {
          const resData = res.data
          const list = resData.records
          if (page === 1) {
            datas.list = list
          } else {
            datas.list = datas.list.concat(list)
          }
          if (resData.total <= datas.list.length) {
            datas.finished = true
          }
        })
      }
      const resetData = () => {
        datas.list = []
      }
      const resetPageData = () => {
        qmpList.value.resetPageData()
      }

      // 获取数据字典
      const getDictData = async () => {
        const dictTypeCodes = ['CTM_TOBE_CUS_MARKET_CHANGE_TYPE']
        datas.dictData = await getDictByPatchType({ dictTypeCodes })
      }

      getDictData()
      return {
        ...toRefs(datas),
        load,
        resetData,
        qmpList,
        resetPageData
      }
    }
  })
</script>
<style lang="less" scoped></style>
